<template>
  <view class="container">
    <view class="header">
      <text class="title">Token测试页面</text>
    </view>
    
    <view class="content">
      <button class="btn" @click="checkToken">检查Token</button>
      <button class="btn" @click="clearToken">清除Token</button>
      
      <view class="info-section">
        <text class="info-title">Token状态:</text>
        <text class="info-content">{{ tokenStatus }}</text>
      </view>
      
      <view class="info-section" v-if="tokenValue">
        <text class="info-title">Token值:</text>
        <text class="info-content token-value">{{ tokenValue }}</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'

const tokenStatus = ref('未检查')
const tokenValue = ref('')

const checkToken = () => {
  try {
    const token = uni.getStorageSync('token')
    if (token) {
      tokenStatus.value = '已登录'
      tokenValue.value = token
    } else {
      tokenStatus.value = '未登录'
      tokenValue.value = ''
    }
  } catch (error) {
    tokenStatus.value = '检查失败: ' + error.message
    tokenValue.value = ''
  }
}

const clearToken = () => {
  try {
    uni.removeStorageSync('token')
    uni.removeStorageSync('userInfo')
    tokenStatus.value = '已清除'
    tokenValue.value = ''
  } catch (error) {
    tokenStatus.value = '清除失败: ' + error.message
  }
}
</script>

<style scoped>
.container {
  height: 100%;
  background-color: #f8f8f8;
  padding: 20px;
}

.header {
  text-align: center;
  margin-bottom: 30px;
}

.title {
  font-size: 24px;
  font-weight: bold;
  color: #333;
}

.content {
  background-color: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.btn {
  width: 100%;
  height: 45px;
  background-color: #07C160;
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  margin-bottom: 15px;
  cursor: pointer;
}

.btn:active {
  background-color: #06AD56;
}

.info-section {
  margin-bottom: 20px;
}

.info-title {
  display: block;
  font-weight: bold;
  margin-bottom: 5px;
  color: #333;
}

.info-content {
  display: block;
  padding: 10px;
  background-color: #f0f0f0;
  border-radius: 5px;
  word-break: break-all;
}

.token-value {
  font-family: monospace;
  font-size: 12px;
}
</style>